<--- %%NOBANNER%% --> nextcells.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| In word document, move the cursor to the next cell in a table;     |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|------------<-- Start of Files or Arguments Needed-->---------------|
| Arguments:                                             |
|  numofcells: after how may cells you want to put your cursor       |
|              into; default is 1 cell per step;                     |
|  insidedata: if the function is used within a data step; the       |
|              second argument can be omitted. Default is "F".       |
|  wordref: is not necessary, default is "wordsys";                  |
|  Note: it doesn't matter which argument comes first, the function  |
|        can recognize numeric or character;                         |
|-------------<-- End of Files or Arguments Needed-->----------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %nextcells(2,T) / %nextcells / %nextcells(T) /            |
|          %nextcells(T,2);                                          |
| Usage: %nextcells(numofcells, insidedata,wordref);                 |
\-------------------<-- End of Files Created-->---------------------*/
%macro nextcells/parmbuff;
/*--------------------------------------------\
| Author:   Duo Zhou;                         |
| Created:  2-27-2001 10:07pm;                |
| Modified: 6-6-2001 9:40pm;                  |
| Purpose:  Move the cursor to the next cell  |
|           in the word document;             |
\--------------------------------------------*/
%local _i_ _j_ npars numofcells insidedata par parcount arg fref numsid wsid rc;
%let parcount=1;
%let par&parcount=%qscan(&syspbuff, &parcount, %str( (),));
  %do %while(%length(&&par&parcount) gt 0);
     %let parcount=%eval(&parcount+1);
     %let par&parcount=%qscan(&syspbuff, &parcount, %str( (),));
  %end;
%let parcount =%eval(&parcount-1);
%if (%quote(%upcase(&par1))=%quote(T)) or (%quote(%upcase(&par1))=%quote(TRUE)) %then %do;
   %let insidedata=%qscan(&syspbuff,1,%str( (),));
   %if &parcount > 1 %then %do;
      %let numofcells=%qscan(&syspbuff,2,%str( (),));
   %end;
   %else %do;
      %let numofcells=;
   %end;
%end;
%else %do;
   %let numofcells=%qscan(&syspbuff,1,%str( (),));
   %if &parcount > 1 %then %do;
      %let insidedata=%qscan(&syspbuff,2,%str( (),));
      %let insidedata=%sysfunc(dequote(&insidedata));
   %end;
   %else %do;
      %let insidedata=F;
   %end;
%end;
%if (%sysfunc(rxmatch(%sysfunc(rxparse($a)),&numofcells))) or (&numofcells eq) %then %do;
   %let numofcells=1;
%end;
/****/
%let arg=%qscan(&syspbuff,-1,%str((),));
%let arg=%sysfunc(dequote(&arg));
%let fref=; %let wsid=0;
%if (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WORDREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINDOW=))) or
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WIN=)))
      %then %do;
   %let fref=%qscan(&arg, 2, %str(= ));
   %put --> Note: Checking the status of window "&fref" to see if it is open.;
%end;
%else %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)),&arg))) and (%quote(%upcase(&arg)) ne %quote(T)) and (%quote(%upcase(&arg))ne %quote(TRUE)) %then %do;
   %if not (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(=))) %then %do; 
      %let fref=%sysfunc(compress(&arg));
      %put --> Note: Checking the status of window "&fref" to see if it is open.;
   %end;
   %else %do;
      %put ==> Alert! Keyword Parameter isn%str(%')t declared!;
   %end; 
%end;
%else %do; 
   %let fref=wordsys;
   %put --> Note: No window reference is specified%str(;) Checking the status of the default; 
   %put -->       window "&fref" to see if it is open.;
%end;
/****/
%if (&fref ne ) %then %do;
   %let wsid=%sysfunc(fopen(&fref,o,132,e));
%end; 
%if &wsid %then %do;
   %let rc=%sysfunc(fclose(&wsid));
   %if (%quote(%upcase(&insidedata)) ne %quote(T)) and (%quote(%upcase(&insidedata)) ne %quote(TRUE)) %then %do;
      data _null_;
      file &fref lrecl=2000;
      %do _i_=1 %to &numofcells;
         put '[NextCell]';
      %end;
      run;
   %end;
   %else %do;
      file &fref lrecl=2000; 
      %do _i_=1 %to &numofcells;
         put '[NextCell]';
      %end;
   %end;
%end;
%else %do;
   %put ==> Alert! Incorrect window reference "&fref", or window "&fref" isn%str(%')t open.;
%end;
%mend nextcells;